#include "stdafx.h"
#include "include.h"
#include "visitor.h"
#include "directui.h"

#include <gtl/io/app_path.h>

namespace gtl
{

namespace dui
{

include::include()
{
}

include::~include()
{
}

bool include::create(gtl::xml& node)
{
	gtl::tstr path;
	visit(&visitor_get_skin_path(path));
	const gtl::tchar* file = node.data();
	if(gtl::tstr_warp(file).empty())
		file = node(_T("src"));

	if(path.empty() || gtl::tstr_warp(file).empty() || m_parent == NULL)
		return false;

	m_xml.load(path + file);

	const gtl::xml::nodes_type& nodes = m_xml.nodes();
	gtl::xml::nodes_type::const_iterator first = nodes.begin();
	gtl::xml::nodes_type::const_iterator last  = nodes.end();
	for(; first != last; ++first)
	{
		gtl::xml& node = *(*first);
		pane* pane_ptr = gtl::dui::factory::instance()->create(node.tag());
		if(pane_ptr == NULL)
			continue;

		m_parent->add(pane_ptr);
		if(!pane_ptr->create(node))
			continue;
	}

	return super::create(node);
}

gtl::xml* include::get_node(const gtl::tchar* name)
{
	return m_xml[name];
}

} // end of namespace dui

} // end of namespace gtl